<%@ page language="java" contentType="text/html; charset=UTF-8"
    import="java.util.*,Entity.User,Biz.inputTestedBeanLocal,javax.naming.InitialContext,javax.naming.Context"
    pageEncoding="UTF-8" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>

        <head>
            <!--Import Google Icon Font-->
            <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
            <!--Import materialize.css-->
            <link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection" />

            <!--Let browser know website is optimized for mobile-->
            <meta name="viewport" content="width=device-width, initial-scale=1.0" />
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>人员录入界面</title>
        </head>
        <script>

            function add() {

                document.Testeds.action = "addTestedServlet";
                if (document.forms["Testeds"]["ID"].value != null && document.forms["Testeds"]["ID"].value != "") {
                    document.Testeds.submit();

                }

            }

            function del() {

                document.Testeds.action = "deleteTestedServlet";
                if (document.forms["Testeds"]["ID"].value != null && document.forms["Testeds"]["ID"].value != "") {
                    document.Testeds.submit();

                }
            }

        </script>

        <body>
            <div class="container">
                <div class="section">
                    <h3>录入被测人</h3>
                    <% Object tmp=session.getAttribute("_inputTestedBean"); session.removeAttribute("ID");
                        session.removeAttribute("name"); inputTestedBeanLocal _inputTestedBean=null; if(tmp==null) {
                        try{ Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
                            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
                            Context context = new InitialContext(jndiProperties);

                            final String appName = "";
                            final String moduleName = "PCR_System";
                            final String distinctName = "";

                            _inputTestedBean=(inputTestedBeanLocal)context.lookup("ejb:" + appName + "/" + moduleName +
                            "/"
                            + distinctName + "/inputTestedBean!Biz.inputTestedBeanLocal?stateful");

                            }
                            catch(Exception e){ e.printStackTrace(); }
                            String tube_ID=request.getParameter("tube_ID");
                            if(!_inputTestedBean.setTubeID(tube_ID))
                            {
                            out.print("id not valid");
                            session.removeAttribute("_inputTestedBean");
                            response.setHeader("refresh","2;URL=inputTubeID.jsp");
                            }
                            session.setAttribute("_inputTestedBean",_inputTestedBean);
                            }
                            else
                            {
                            _inputTestedBean=(inputTestedBeanLocal)tmp;

                            }
                            request.setAttribute("tube_id", _inputTestedBean.getTubeID());
                            request.setAttribute("Testeds", _inputTestedBean.getTesteds());


                            %>
                            <h4>试管编号:${tube_id}</h4>
                            <div class="row">
                                <table>
                                    <thead>
                                        <tr>
                                            <th>学号</th>
                                            <th>姓名</th>

                                        </tr>
                                    </thead>

                                    <tbody>
                                        <c:forEach items="${Testeds}" var="Tested">
                                            <tr>
                                                <td>${Tested.id}</td>
                                                <td>${Tested.name}</td>
                                            </tr>
                                        </c:forEach>

                                    </tbody>
                                </table>
                            </div>
                            <div class="divider"></div>

                            <form name="Testeds" action="addTestedServlet" method="get">
                                <div class="row">

                                    <div class="input-field col l4 offset-l4">
                                        <input id="ID" name="ID" type="text" class="validate" required="required" />
                                        <label for="ID">学号</label>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col l2 offset-l4">
                                        <button class="btn waves-effect waves-light" onclick="add()">
                                            添加学生
                                        </button>
                                    </div>
                                    <div class="col l2">

                                        <button class="btn waves-effect waves-light" type="button" onclick="del()">
                                            删除学生
                                        </button>
                                    </div>
                                    <div class="col l2">

                                        <button class="btn waves-effect waves-light" type="button"
                                            onclick="window.location.href='submitTubeServlet'">
                                            提交试管
                                        </button>
                                    </div>
                                </div>
                            </form>
                </div>
            </div>
            <!--Import jQuery before materialize.js-->
            <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
            <script type="text/javascript" src="js/materialize.min.js"></script>
        </body>

        </html>